<?php
include 'login.php';
require_once 'version.php';
?>
<HTML>
<HEAD>
<TITLE>NZBGet Web Interface</TITLE>

<style TYPE="text/css">
<!--
<?php include 'style.css' ?>
-->
</style>

<script type="text/javascript"><!--

	var secondsToUpdate = -1
	var timerID = 0
	var xmlhttp
	var firstLoad = true
	var inputdownloadlimit_focused=false
	var inputdownloadlimit_needupdate=false

	function updatestatus(url) {
		clearTimeout(timerID)
		document.getElementById("updateseconds").innerHTML="<center>Loading...</center>"
	
		if (window.XMLHttpRequest) // code for all new browsers
			xmlhttp = new XMLHttpRequest()
		else if (window.ActiveXObject){ // code for IE5 and IE6
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
		}
		
		if (xmlhttp==null)
		{
			alert("Your browser does not support XMLHTTP.")
			return
		}		
			
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open('GET', url, true)
		xmlhttp.send(null)
	}

	function state_Change()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status==200) 
		{
			document.getElementById('status').innerHTML=xmlhttp.responseText
			statusLoaded();
		}
	}

	function removeUploadStatus()
	{
		if (document.getElementById("uploadstatus").innerHTML != "")
		{
			document.getElementById("uploadstatus").innerHTML=""
		}
	}

	function removeNewzbinStatus()
	{
		if (document.getElementById('newzbinstatus') &&
			document.getElementById("newzbinstatus").innerHTML != "")
		{
			document.getElementById("newzbinstatus").innerHTML=""
		}
	}

	function countSeconds()
	{
		secondsToUpdate -= 1;
		if (secondsToUpdate <= 0)
		{
			refreshIt()		
		}
		else
		{
			document.getElementById("updateseconds").innerHTML="<center>Next update in " + secondsToUpdate + " seconds</center>"
			timerID = setTimeout('countSeconds()', 1000)
		}
	}

	function refreshIt()
	{
		if (firstLoad)
		{
			firstLoad = false
			updatestatus('status.php?groupmode=1')
		}
		else
			updatestatus('status.php')
	}

	function statusLoaded()
	{
		if (document.getElementById('serverinfohidden')) {
			document.getElementById('serverinfo').innerHTML=document.getElementById('serverinfohidden').innerHTML
		} else {
			document.getElementById('serverinfo').innerHTML='<center>NZBGet Web Interface <?php echo $webversion; ?></center><br>'
		}
		if (document.getElementById('servercommandhidden')) {
			document.getElementById('servercommand').innerHTML=document.getElementById('servercommandhidden').innerHTML
		} else {
			document.getElementById('servercommand').innerHTML='<center>Control panel</center><br>'
		}
		if (document.getElementById('usermenuhidden')) {
			document.getElementById('usermenu').innerHTML=document.getElementById('usermenuhidden').innerHTML
		}
		if (inputdownloadlimit_needupdate || !inputdownloadlimit_focused) 
		{
			document.getElementById('inputdownloadlimit').value=document.getElementById('downloadlimit').innerHTML
			inputdownloadlimit_needupdate = false;
		}
		
		if (document.getElementById('uploadstatushidden'))
			document.getElementById('uploadstatus').innerHTML="<br>"+document.getElementById('uploadstatushidden').innerHTML

		if (document.getElementById('newzbinstatushidden'))
			document.getElementById('newzbinstatus').innerHTML="<br>"+document.getElementById('newzbinstatushidden').innerHTML;

		secondsToUpdate=document.getElementById('updateinterval').innerHTML
		if (secondsToUpdate > 0)
		{
			document.getElementById('updateseconds').innerHTML='<center>Next update in ' + secondsToUpdate + ' seconds</center>'
			timerID = setTimeout('countSeconds()', 1000)
		} else {
			document.getElementById('updateseconds').innerHTML='<center>click <a href="javascript:updatestatus(\'status.php\')">refresh</a> to update</center>'
		}

		setTimeout('removeUploadStatus()', 31000)
		setTimeout('removeNewzbinStatus()', 31000)
	}

	function pageLoaded()
	{
		setTimeout('refreshIt()', 0)
	}
	
	function IsEnterKey(e)
	{
		var keynum;
		if(window.event) // IE
		  keynum = e.keyCode;
		else if(e.which) // Netscape/Firefox/Opera
		  keynum = e.which;
		return keynum == 13;
	}

	function SetRate()	
	{
		inputdownloadlimit_needupdate = true
		updatestatus('status.php?rate='+document.getElementById('inputdownloadlimit').value);
	}
	
	function ShutdownServer()
	{
		var answer = confirm("Shutdown NZBGet-Server?");
		if (answer){
			updatestatus('status.php?action=shutdown');
		}
	}

//--></script>
</HEAD>

<div class = "top">
	NZBGet Web Interface <?php echo $webversion; ?><center>
</div>
<BODY onLoad="pageLoaded()">
<table width="100%">
<tr>
<td width="240" valign="top">

<!--PPWeb-->
<div class = "block">
<center><B><A HREF="/ppweb/index.html">PPWeb</A></B> <small>(<A HREF="/ppweb/ppweb/cgi-bin/ppweb_update.cgi">u</A>)</small></center><br>

<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?do=Nzbsorg_browse">NzbsOrg</A>&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?do=Nzbtv_browse">Nzbtv</A>&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?do=Nzbsin_browse">Nzbsin</A>&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?do=Nzbsu_browse">Nzbsu</A>&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?do=Dognzb_browse">Dognzb</A>&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?do=Pwnzb_browse">Pwnzb</A>&nbsp;&nbsp;
<br><br>

Downloads:&nbsp;&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/nzbget_ppweb.cgi?hold">On Hold</A>&nbsp;&nbsp;&nbsp;
<br>
<A HREF="/ppweb/ppweb/cgi-bin/nzbget_ppweb.cgi?list">In Progress</A>&nbsp;&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/nzbget_ppweb.cgi?save">Complete</A>
<br><br>

Logs:&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?tail_log=status.log">status</A>&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?tail_log=ppweb.log">ppweb</A>&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?tail_log=nzbget.log">nzbget</A>
<br><br>

<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?watchlist">Watch List</A>&nbsp;&nbsp;&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/wfnzb.cgi?upload">Upload nzb</A>&nbsp;&nbsp;&nbsp;
<br><br>

<form action="/ppweb/ppweb/cgi-bin/ppweb_db.cgi" method="post">
<INPUT TYPE="hidden" NAME="do" value="search_db"> 
<INPUT TYPE="text" SIZE="15" NAME="kw" value=""> 
<input type="submit" value="Find"></form>

</div>
<!--NZBGet-->
<div class = "block">
<center><B>NZBGet</B>&nbsp;&nbsp;&nbsp;<a href="http://192.168.1.1:6788">Webui</A></center><br>

View:&nbsp;&nbsp;&nbsp;
<a href="javascript:updatestatus('status.php?groupmode=1&amp;page=1&amp;logpage=1')">groups</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:updatestatus('status.php?filemode=1&amp;page=1&amp;logpage=1')">files</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:updatestatus('status.php')">refresh</a>
<br><br>

Downloading:&nbsp;&nbsp;&nbsp;
<a href="javascript:updatestatus('status.php?action=pause')">pause</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:updatestatus('status.php?action=resume')">resume</a>
<br><br>

Daemon:&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/nzbget_ppweb.cgi?start">start</A>&nbsp;
<A HREF="/ppweb/ppweb/cgi-bin/nzbget_ppweb.cgi?stop">stop</A>&nbsp;&nbsp;
<A HREF="config.php">Configure</A>
<br><br>

Max rate:
<input type="text" class="inputrate" name="rate" id="inputdownloadlimit" value="" onFocus="inputdownloadlimit_focused=true" onBlur="inputdownloadlimit_focused=false" onkeydown="if (IsEnterKey(event)) SetRate()">
KB/s&nbsp;<input type="button" value="Set" onClick="SetRate()">

</div>
<!--end_mod-->

<?php
	if (isset($NewzbinUsername) && $NewzbinUsername != '')
	{
?>

<div class="block"><center>Fetch Newzbin Report</center><br>
<form enctype="multipart/form-data" action="status.php" method="post">
Report ID: <input class="inputnewzbin" name="newzbinid" type="text"/>
<input class="submit" type="submit" value="Fetch" />
</form>
<div class="block">
<center>fetch status</center>
<div id="newzbinstatus"></div>
</div>
</div>

<?php
	}
?>

<div class = "block" id="serverinfo"><center>Server information</center><br></div>

<div class = "block" id="servercommand"><center>Server control</center><br></div>

<?php
if (is_readable('usermenu.php')) {
?>
<div class = "block" id="usermenu"><center>User menu</center><br></div>
<?php
}
?>

<div class = "block" id="updateseconds">
<center>Loading...</center>
</div>

</td>

<td valign="top">
<div id="status"></div>
</td>

</tr>

</table>

</BODY>
</HTML>
